package com.boot.app.base.controller;

import com.boot.api.ApiResult;
import com.boot.app.base.service.IBaseMenuService;
import com.boot.app.base.service.IBaseUserService;
import com.boot.app.base.vo.MenuInfo;
import com.boot.app.base.vo.UserVO;
import com.boot.app.system.service.ISystemCodeService;
import com.boot.app.system.vo.CodeInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "BaseController", description = "基础信息")
@RestController
@RequestMapping("base")
public class BaseController {

    private final IBaseUserService userService;

    private final IBaseMenuService menuService;

    private final ISystemCodeService codeService;


    @Autowired
    public BaseController(
        IBaseUserService userService,
        IBaseMenuService menuService,
        ISystemCodeService codeService
    ){
        this.menuService = menuService;
        this.userService = userService;
        this.codeService = codeService;
    }

    @Operation(summary = "获取用户信息")
    @GetMapping("userinfo")
    public ApiResult<UserVO> getUserInfo(){
        UserVO userVO = userService.fetchUserInfo();
        return ApiResult.success(userVO);
    }

    @Operation(summary = "获取菜单信息")
    @GetMapping("menuinfo/{roleId}")
    public ApiResult<List<MenuInfo>> getMenuInfo(@PathVariable("roleId") long roleId){
        List<MenuInfo> list = menuService.fetchMenuInfo(roleId);
        return ApiResult.success(list);
    }

    @Operation(summary = "获取词典信息")
    @GetMapping("codeinfo")
    public ApiResult<List<CodeInfo>> getCodeInfo(){
        List<CodeInfo> list = codeService.fetchCodeInfo();
        return ApiResult.success(list);
    }

}
